<template>
	<view>

		<uni-popup ref="addStudent" type="bottom" @maskClick="close()">
			<view class="bg-white ">
				<uni-section :title="title" type="circle">
					<template v-slot:right>
						<view @click="close">关闭</view>
					</template>
				</uni-section>



				<!-- 搜索框 -->


				<uni-forms class="margin-sm" label-width="150rpx" ref="form" :modelValue="from" :rules="rules">
					<uni-forms-item label="课包类型" required name="offlineCurriculumType">
						<uni-data-checkbox mode="button" v-model="from.offlineCurriculumType"
							:localdata="dict.offline_curriculum_type"
							:map="{text:'dictName',value:'dictValue'}"></uni-data-checkbox>
					</uni-forms-item>

					<uni-forms-item label="排课类型" required name="offlineClassType">
						<uni-data-checkbox mode="button" v-model="from.offlineClassType"
							:localdata="dict.offline_class_type"
							:map="{text:'dictName',value:'dictValue'}"></uni-data-checkbox>
					</uni-forms-item>


					<uni-forms-item label="课程名称" required name="offlineClassName">
						<uni-data-select v-model="from.offlineClassName" :localdata="dict.offline_class_name"
							placeholder="选择课程名称"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="时间段" required name="sysTimeSlotId">
						<uni-data-select v-model="from.sysTimeSlotId" :localdata="getcommon('shijianduan')"
							placeholder="请选择时间段"></uni-data-select>
					</uni-forms-item>

					<uni-forms-item label="教室" required name="sysClassroomId">
						<uni-data-select v-model="from.sysClassroomId" :localdata="dict.sysClassroomList"
							@change="getContract" placeholder="选择课程类型"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="主讲老师" required name="principalTeacher">
						<uni-data-select v-model="from.principalTeacher" :localdata="dict.createUserNameList"
							placeholder="选择主讲老师"></uni-data-select>
					</uni-forms-item>


					<uni-forms-item label="辅助老师">
						<uni-data-select v-model="from.assistantTeacher" :localdata="dict.createUserNameList"
							placeholder="选择辅助老师"></uni-data-select>
					</uni-forms-item>

					<uni-forms-item label="上课日期" required name="startClassDate">
						<uni-datetime-picker type="date" v-model="from.startClassDate" />
					</uni-forms-item>




					<uni-forms-item label="耗课数" required name="offlineClassKeshishu">
						<uni-easyinput v-model="from.offlineClassKeshishu" type="number"></uni-easyinput>
					</uni-forms-item>





					<uni-forms-item label="学生容量" required name="capacity">
						<uni-easyinput v-model="from.capacity" type="number"></uni-easyinput>

					</uni-forms-item>


				</uni-forms>
				<view class="padding-bottom-lg margin-top-lg" style="padding :0px 20rpx 50rpx 20rpx">

					<view style="display: flex;">
						<view style="flex: 3;" @click="save">
							<text class="login-btn cu-btn block bg-blue lg round">确认</text>
						</view>

					</view>
				</view>

			</view>
		</uni-popup>

	</view>
</template>

<script>
	import {
		isNull
	} from "@/utils/validate";
	import {
		doInsert,
		doUpdate
	} from "@/api/system/academicAffairsCenter/offlineTimetable/SysOfflineTimetableManagementApi";

	import {
		getListByParentOrStudent
	} from "@/api/marketing/customer/CustomerManagementApi";
	import {
		getListById
	} from "@/api/vip/contract/VipContractManagementApi";
	import {
		getcommon
	} from "@/utils/common.js";
	export default {
		components: {

		},
		data() {
			return {
				title: '',
				customerList: [],
				queryForm: {
					pageNo: 1,
					pageSize: 100,
					createTime_ORDER: "DESC",
					offlineTimetableId_EQ: null
				},
				from: {
					isShiting: null,
					offlineCurriculumType: null,
					vipContractId: null,
					izUsable: '1',
					ischaban: '',
				},
				dict: {
					offline_class_name: []
				},
				query: null,
				vipContractList: [],
				rules: {

					offlineCurriculumType: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					offlineClassType: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					offlineClassName: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					startClassDate: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					sysTimeSlotId: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					sysClassroomId: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					offlineClassKeshishu: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					principalTeacher: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					capacity: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					}

				},
			}
		},
		mounted() {

		},
		methods: {

			getcommon(fide) {

				return getcommon(fide);
			},
			save() {

				this.$refs['form'].validate().then(async res => {
					if (!isNull(this.from.id)) {
						const {
							success,
							msg
						} = await doUpdate(this.from);
						if (success) {

						}
					} else {
						const {
							success,
							msg
						} = await doInsert(this.from);
						if (success) {

						}
					}

					this.close();

				})

			},

			open(data) {
				Object.assign(this.$data, this.$options.data());
				this.dict.offline_curriculum_type = this.$getDictList("offline_curriculum_type");
				this.dict.offline_class_type = this.$getDictList("offline_class_type");
				this.dict.longTerm = this.$getDictList("longTerm");
				this.dict.createUserNameList = getcommon("createUserNameList");

				for (let s of this.dict.createUserNameList) {

					s.text = s.realName
					s.value = s.id
				}

				this.dict.offline_class_name = this.$getDictList("offline_class_name");
				for (let s of this.dict.offline_class_name) {
					s.text = s.dictName
					s.value = s.dictValue
				}
				this.dict.sysClassroomList = getcommon('sysClassroomList')
				for (let s of this.dict.sysClassroomList) {
					s.text = s.name
					s.value = s.id
				}


				if (data.id == null) {
					this.title = "添加班级"
				} else {
					this.title = "编辑班级"
					this.from = data
				}



				this.$refs.addStudent.open()

			},

			close() {
				Object.assign(this.$data, this.$options.data());
				this.$refs.addStudent.close()
				// uni.showTabBar();
				this.$emit('refresh')
			},
		}
	}
</script>

<style>
</style>